﻿//using UnityEngine;
//using System.Collections;

//public class AIEnemy : RaycastCharacterInput,IEnemy {
//    public BoxCollider2D[] geometry;
//    public RaycastCharacterController2D me;
//    public float xDelta = 0.5f;
//    public float yDelta = 0.25f;
//    public float jumpHeight;
//    public float jumpDistance;
//    public float decideTime = 0.5f;


//    public RaycastCharacterController2D targetController;

//    private Transform target;

//    private float goalPosition;
//    private float moveDirection;


//    private bool fall;
//    private float fallDirection;
	
//    void Start () {
//        target = targetController.transform;
//        InvokeRepeating("Decide", decideTime, decideTime);
//    }
	
	
//    public void Decide()
//    {
//        x = 0.0f; y = 0.0f;
//        jumpButtonDown = false; jumpButtonHeld = false;

       
//        if (me.State == CharacterState.JUMPING || me.State == CharacterState.FALLING || me.State == CharacterState.AIRBORNE)
//        {
//            x = moveDirection / 1.1f;
//        }
//        else
//        {
//            AIAction currentAction = DecideOnAction();
          
//            switch (currentAction)
//            {
//                case (AIAction.JUMP_TO_PLATFORM):
//                    if (Mathf.Abs(goalPosition - transform.position.x) < xDelta)
//                    {
//                        x = moveDirection / 1.1f;
//                        jumpButtonDown = true;
//                    }
//                    else
//                    {
//                        if (goalPosition > transform.position.x)
//                        {
//                            x = 1.0f / 1.1f;
//                        }
//                        else
//                        {
//                            x = -1.0f / 1.1f;
//                        }
//                    }
//                    break;
//                case (AIAction.JUMP_AT_CHARACTER):
                   
//                    x = moveDirection;
//                    jumpButtonDown = true;
//                   // Debug.Log(AIAction.JUMP_AT_CHARACTER);
//                    break;
//                case (AIAction.FALL_OFF_LEDGE):
//                    x = moveDirection;
//                //    Debug.Log(AIAction.FALL_OFF_LEDGE);
//                    break;
//                case (AIAction.WALK_TOWARDS_TARGET):
//                    x = moveDirection;
//                //    Debug.Log(AIAction.WALK_TOWARDS_TARGET);
//                    break;
//            }
//        }
//    }

//    private AIAction DecideOnAction()
//    {
//        BoxCollider2D climbTarget = null;
//        float climbTargetPosition = transform.position.x;
//        BoxCollider2D current = null;
//        foreach (RaycastCollider2D feetCollider in me.feetColliders)
//        {
//            RaycastHit2D collision = feetCollider.GetCollision(1 << me.backgroundLayer | 1 << me.passThroughLayer, 0.01f);
//            if (collision.collider != null && collision.collider is BoxCollider2D)
//            {
//                current = (BoxCollider2D)collision.collider;
//                break;
//            }
//        }
       

//        if (target.position.y > transform.position.y &&
//            (targetController.GroundedFeetCount > 0 || target.position.y > transform.position.y + yDelta + jumpHeight) &&
//            (me.State != CharacterState.JUMPING && me.State != CharacterState.FALLING && me.State != CharacterState.AIRBORNE))
//        {

           
//            if (current != null)
//            {
//                float highest = -9999;
//                float closest = 9999;
//                foreach (BoxCollider2D c in geometry)
//                {
//                    if (c != current && Max(c).y < Max(current).y + jumpHeight)
//                    {
                       
//                        if (Min(c).x > Min(current).x && Min(c).x < Max(current).x + jumpDistance)
//                        {
//                            if (Max(c).y > highest)
//                            {
//                                climbTargetPosition = Mathf.Min(Max(current).x , Min(c).x - (jumpDistance / 2.0f));
//                                climbTarget = c;
//                                highest =Max(c).y;
//                                closest = Mathf.Abs(climbTargetPosition - transform.position.x);
//                                moveDirection = 1;
//                            }
//                        }
//                        if (Max(c).x < Max(current).x && Max(c).x > Min(current).x - jumpDistance)
//                        {
//                            if (Max(c).y > highest)
//                            {
//                                climbTargetPosition = Mathf.Max(Min(current).x, Max(c).x + (jumpDistance / 2.0f));
//                                climbTarget = c;
//                                highest = Max(c).y;
//                                moveDirection = -1;
//                            }
                           
//                            else if (climbTarget == c && closest > Mathf.Abs(Mathf.Max(Min(current).x, Max(c).x + (jumpDistance / 2.0f)) - transform.position.x))
//                            {
//                                climbTargetPosition = Mathf.Max(Min(current).x, Max(c).x + (jumpDistance / 2.0f));
//                                moveDirection = -1;
//                            }
//                        }
//                    }
//                }
//            }
//        }

//        if (climbTarget != null)
//        {
//            goalPosition = climbTargetPosition;
//            return AIAction.JUMP_TO_PLATFORM;
//        }

      
//        float enemyDirection;
//        if (target.position.x > transform.position.x)
//        {
//            enemyDirection = 1.0f;
//        }
//        else
//        {
//            enemyDirection = -1.0f;
//        }
     
       
//        if (targetController.GroundedFeetCount == 0 && target.position.y > transform.position.y && Mathf.Abs(target.position.x - transform.position.x) < xDelta * 3.0f)
//        {
//            moveDirection = 0;
//            return AIAction.JUMP_AT_CHARACTER;
//        }

        
//        if (current != null && target.position.y < transform.position.y + yDelta)
//        {
//            foreach (BoxCollider2D c in geometry)
//            {
//                if (Max(c).x < Max(current).x && Max(c).x> Min(current).x && Max(c).y < Max(current).y)
//                {
//                    moveDirection = -1.0f;
//                    return AIAction.FALL_OFF_LEDGE;
//                }
//                else if (Min(c).x < Max(current).x && Min(c).x>Min(current).x && Max(c).y <Max(current).y)
//                {
//                    moveDirection = 1.0f;
//                    return AIAction.FALL_OFF_LEDGE;
//                }
//            }
//        }



       
//            if (Mathf.Abs(target.position.x - transform.position.x) > xDelta)
//                {
           
//                moveDirection = enemyDirection;
//                return AIAction.WALK_TOWARDS_TARGET;
//                }

        
       

//        return AIAction.NONE;
//    }

//    private enum AIAction
//    {
//        NONE,
//        WALK_TOWARDS_TARGET,
//        FALL_OFF_LEDGE,
//        JUMP_TO_PLATFORM,
//        JUMP_AT_CHARACTER
//    }
//    public  Vector2 Max(this Collider2D collider)
//    {
//        if (collider is BoxCollider2D)
//            return (Vector2)collider.gameObject.transform.position + 
//                new Vector2(collider.gameObject.transform.localScale.x * (((BoxCollider2D)collider).center.x + (((BoxCollider2D)collider).size.x / 2)), collider.gameObject.transform.localScale.y * (((BoxCollider2D)collider).center.y + (((BoxCollider2D)collider).size.y / 2)));
       
//        return Vector2.zero;
//    }

//    public  Vector2 Min(this Collider2D collider)
//    {
//        if (collider is BoxCollider2D) return (Vector2)collider.gameObject.transform.position +
//            new Vector2(collider.gameObject.transform.localScale.x * (((BoxCollider2D)collider).center.x - (((BoxCollider2D)collider).size.x / 2)),
//                        collider.gameObject.transform.localScale.y * (((BoxCollider2D)collider).center.y - (((BoxCollider2D)collider).size.y / 2)));

       
//        return Vector2.zero;
//    }


//    public void Kill()
//    {
//        throw new System.NotImplementedException();
//    }

//    public void KillFromBelow(float force)
//    {
//        throw new System.NotImplementedException();
//    }

//    public void KillFromAbove(HitBox other, Collider me)
//    {
//        throw new System.NotImplementedException();
//    }
//}
